Add WebSocket support to SITL for PWA Configurator#42
Add WebSocket support to SITL for PWA Configurator#42sensei-hacker wants to merge 1 commit intomaintenance-9.xfrom
Conversation
This commit adds native WebSocket server support to INAV SITL, enabling browser-based Progressive Web App (PWA) configurators to connect directly without requiring Electron or TCP proxy bridges. Key Features: - RFC 6455 compliant WebSocket server implementation - Self-contained (no external dependencies - includes SHA-1, Base64) - Runs on ports 5771-5778 (base 5770 + UART ID) - Coexists with existing TCP ports (5760-5761) - Binary frame encoding/decoding with proper masking - Thread-safe receive handling via pthread Implementation: - New files: * src/main/drivers/serial_websocket.h - API and structures * src/main/drivers/serial_websocket.c - Full WebSocket implementation - Modified files: * src/main/io/serial.c - uartOpen() returns WebSocket port for MSP * src/main/target/SITL/target.c - WebSocket initialization * cmake/sitl.cmake - Build integration Testing: - Verified with Python websockets client - Byte-level validation confirms proper frame encoding/decoding - MSP protocol integrity preserved (tested with MSP_IDENT) - Browser test client included: tools/websocket_test_client.html WebSocket Ports: - UART1: ws://localhost:5771 - UART2: ws://localhost:5772 - UART3-8: ws://localhost:5773-5778 This enables INAV Configurator PWA to connect directly to SITL without the TCP-to-WebSocket bridge workarounds discussed in issue iNavFlight#123. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||||||||||
User description
Summary
Adds native WebSocket server support to INAV SITL, enabling browser-based Progressive Web App (PWA) configurators to connect directly without requiring Electron or TCP proxy bridges.
Key Features
Implementation Details
New Files:
src/main/drivers/serial_websocket.h- WebSocket API and structuressrc/main/drivers/serial_websocket.c- Full WebSocket implementation (550+ lines)Modified Files:
src/main/io/serial.c- uartOpen() returns WebSocket port for MSPsrc/main/target/SITL/target.c- WebSocket initializationcmake/sitl.cmake- Build integrationTesting
Test Results:
WebSocket Ports
ws://localhost:5771ws://localhost:5772ws://localhost:5773-5778Use Case
This enables INAV Configurator PWA to connect directly to SITL without the TCP-to-WebSocket bridge workarounds, making browser-based testing and development seamless.
PR Type
Enhancement, New Feature
Description
Adds RFC 6455 compliant WebSocket server to SITL for PWA Configurator
Enables browser-based direct connection without TCP proxy bridges
Implements self-contained SHA-1 and Base64 for handshake authentication
Runs on ports 5771-5778 (base 5770 + UART ID) alongside TCP ports
Includes binary frame encoding/decoding with proper client masking support
Thread-safe receive handling via pthread mutex and dedicated receive thread
Diagram Walkthrough
File Walkthrough
serial_websocket.h
WebSocket header with port structure and API definitionssrc/main/drivers/serial_websocket.h
wsPort_t) with socket, thread, andbuffer management
wsOpen(),wsReceiveBytesEx(),wsRXBytesFree()size
serial_websocket.c
Complete WebSocket server implementation with frame handlingsrc/main/drivers/serial_websocket.c
Base64 encoding
opcode handling
mirroring TCP implementation
receive thread
transmission
serial.c
Route SITL UART to WebSocket instead of TCPsrc/main/io/serial.c
serial_websocket.hheaderuartOpen()to usewsOpen()instead oftcpOpen()for SITLbuilds
target.c
Add WebSocket header include to SITL targetsrc/main/target/SITL/target.c
serial_websocket.hheader to enable WebSocketinitialization
sitl.cmake
Include WebSocket sources in SITL build configurationcmake/sitl.cmake
drivers/serial_websocket.canddrivers/serial_websocket.hto SITLbuild sources
--no-warn-rwx-segmentsdue tocompatibility issues